/**
 * 
 */
package com.risetek.tft.context;

import java.util.Map;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;

import com.risetek.tft.entity.TSysConfig;
import com.risetek.tft.service.SysconfigService;

/**
 * @author hetao
 * 
 */
public class Sysconfig {

	@Autowired
	private SysconfigService sysconfigService;
	public void setSysconfigService(SysconfigService sysconfigService) {
		this.sysconfigService = sysconfigService;
	}
	private static Sysconfig sysconfig;

	@PostConstruct
	public void init() {
		sysconfig = this;
		sysconfig.sysconfigService = this.sysconfigService;
		System.out.println(""
			    
 +"                  _ooOoo_\r\n"
 +"                 o8888888o\r\n"
 +"                 88\" . \"88\r\n"
 +"                 (| -_- |)\r\n"
 +"                 O\\  =  /O\r\n"
 +"              ____/`---'\"____\r\n"
 +"            .'  \\|     |//  `.\r\n"
 +"           /  \\|||  :  |||//  \\\r\n"
 +"          /  _||||| -:- |||||-  \\\r\n"
 +"          |   | \\\\  -  /// |   |\r\n"
 +"          | \\_|  ''\\---/''  |   |\r\n"
 +"          \\  .-\\__  `-`  ___/-. /\r\n"
 +"        ___`. .'  /--.--\\  `. .\" __\r\n"
 +"     .\"\" '<  `.___\\_<|>_/___.'  >'\"\".\r\n"
 +"    | | :  `- \\`.;`\\ _ /`;.`/ - ` : | |\r\n"
 +"    \\  \\ `-.   \\_ __\\ /__ _/   .-` /  /\r\n"
 +"======`-.____`-.___\\_____/___.-`____.-'======\r\n"
 +"                 `=---='\r\n"
+"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n"
+" 佛祖保佑       永无BUG\r\n"
+"\r\n"
+"        佛曰:\r\n"    
+"                  写字楼里写字间，写字间里程序员；\r\n "   
+"                  程序人员写程序，又拿程序换酒钱。\r\n"    
+"                  酒醒只在网上坐，酒醉还来网下眠；\r\n "   
+"                  酒醉酒醒日复日，网上网下年复年。\r\n"    
+"                  但愿老死电脑间，不愿鞠躬老板前； \r\n"   
+"                  奔驰宝马贵者趣，公交自行程序员。  \r\n " 
+"                  别人笑我忒疯癫，我笑自己命太贱；  \r\n"  
+"                  不见满街漂亮妹，哪个归得程序员？");
	} 
	
	public static String get(String key, String defValue) {
		TSysConfig config = sysconfig.sysconfigService.findById(1);
		Map<String, String> map = config.getConfig();
		String value = map.get(key);
		return value == null ? defValue : value;
	}

	public static String get(String key) {
		try {
			TSysConfig config = sysconfig.sysconfigService.findById(1);
			Map<String, String> map = config.getConfig();
		} catch (Exception e) { 
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return get(key, "");
	}
	
	public static int getInt(String key, int defValue) {
		TSysConfig config = sysconfig.sysconfigService.findById(1);
		Map<String, String> map = config.getConfig();
		String value = map.get(key);
		return value == null ? defValue : Integer.parseInt(value);
	}
	
	public static int getInt(String key) {
		TSysConfig config = sysconfig.sysconfigService.findById(1);
		Map<String, String> map = config.getConfig();
		return getInt(key, 0);
	}
	
	public static Map<String, Object> getAll() {
		TSysConfig config = sysconfig.sysconfigService.findById(1);
		return config.getConfig();
	}

}
